package com.pan.games.threadgame;

import com.pan.games.threadgame.communicate.ShareCommunicate;
import lombok.extern.slf4j.Slf4j;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2020/12/15
 */
@Slf4j
public class WaterThread extends Thread {


    public WaterThread(){
        this.setName("WatherThread");

    }

    //覆盖Thread类中的run方法.
    @Override
    public void run() {
        log.info("my name is:"+this.getName());
        //3):在run方法中编写需要执行的操作
        for(int i = 0; i < 10; i ++){
            log.info("water is making life:" +i+".");
        }
        while(true){
            if(ShareCommunicate.volatileNotice){
                System.out.println(currentThread().getName()+"已经收到了volatileNotice");
                break;
            }
        }
        while(true){
            if(ShareCommunicate.commonNotice){
                System.out.println(currentThread().getName()+"已经收到了commonNotice");
                break;
            }
        }

    }
}
